﻿<%@ Page Language="C#" MasterPageFile="~/WebForm/MasterPage.master" AutoEventWireup="true" CodeFile="ManageRoad.aspx.cs" Inherits="WebForm_ManageRoad_ManageRoad" %>
<%@ Register assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI" tagprefix="asp" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@ Register Namespace="My" TagPrefix="cc2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript" language="javascript">
    function OpenFile(strID, thetime) {
        window.showModalDialog('ManageRoadItem.aspx?RoadID=' + strID + '&thetime=' + thetime, 'RoadItemName', 'dialogHeight:500px;dialogWidth:800px;status:no,resizable:no,scrollbars:auto,toolbar:no,location:no,menubar:no;'); return false;

    }     
</script>


        <asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <TABLE width="100%"><TBODY>
        <tr>
            <td align="right">
                <asp:HyperLink ID="hlinkDescription" SkinID="Description" runat="server" NavigateUrl="~/Public/Description/RoadManage.html"></asp:HyperLink>
            </td>
        </tr>
                <TR><TD><asp:FormView id="fv" runat="server" DataKeyNames="id" DataSourceID="SqlDataSource2" DefaultMode="Insert" Width="98%" OnDataBound="fv_DataBound" OnItemInserting="fv_ItemInserting"><InsertItemTemplate>
<TABLE cellSpacing=0 cellPadding=0 border=0><TBODY><TR><TD colSpan=2><cc1:ConfirmButtonExtender id="ConfirmButtonExtender1" runat="server" TargetControlID="InsertButton" ConfirmText="確定要新增?" __designer:wfdid="w54">
                            </cc1:ConfirmButtonExtender> <asp:Label id="lblRegionName" runat="server" Text="鄉鎮市：" __designer:wfdid="w55"></asp:Label><asp:DropDownList id="ddlRegionID" runat="server" OnDataBound="ddlRegionID_DataBound" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="ddlRegionID_SelectedIndexChanged" DataValueField="RegionID" DataTextField="RegionName" AutoPostBack="True" __designer:wfdid="w56">
                            </asp:DropDownList><asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ValidationGroup="vInsert" SetFocusOnError="True" InitialValue="0" ErrorMessage="請選擇鄉鎮市!!" Display="None" ControlToValidate="ddlRegionID" __designer:wfdid="w57"></asp:RequiredFieldValidator><BR /><asp:Label id="lblRoadName" runat="server" Text="道路總稱：" __designer:wfdid="w58"></asp:Label><asp:TextBox id="txtRoadName" runat="server" Width="350px" MaxLength="100" __designer:wfdid="w59"></asp:TextBox> <asp:SqlDataSource id="SqlDataSource1" runat="server" SelectCommand="SELECT * FROM [Region] WHERE ([RegionType] = @RegionType) ORDER BY [Sequence]" ConnectionString="<%$ ConnectionStrings:connStr %>" __designer:wfdid="w60">
                                    <SelectParameters>
                                        <asp:Parameter DefaultValue="T" Name="RegionType" Type="String" />
                                    </SelectParameters>
                                </asp:SqlDataSource> <asp:LinkButton id="InsertButton" runat="server" ValidationGroup="vInsert" Text="新增" CommandName="Insert" CausesValidation="True" __designer:wfdid="w61"></asp:LinkButton></TD></TR></TBODY></TABLE>
</InsertItemTemplate>
</asp:FormView><asp:SqlDataSource id="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:connStr %>" InsertCommand="INSERT INTO [FD_Road] ([Parent], [RoadName]) VALUES (@Parent, @RoadName)" DeleteCommand="DELETE FROM [FD_Road] WHERE [RoadID] = @RoadID;DELETE FROM [FD_RoadItem] WHERE [RoadID] = @RoadID" SelectCommand="SELECT * FROM [FD_Road] a join region b on a.Parent=b.RegionID WHERE (a.Parent = @Parent or @Parent='0') ORDER BY b.Sequence,[RegionName],[RoadName]" UpdateCommand="UPDATE [FD_Road] SET [Parent] = @Parent, [RoadName] = @RoadName WHERE [RoadID] = @RoadID">
                        <InsertParameters>
                            <asp:Parameter Name="Parent" Type="String" />
                            <asp:Parameter Name="RoadName" Type="String" />
                        </InsertParameters>
                        <SelectParameters>
                            <asp:Parameter Name="Parent" Type="String" />
                        </SelectParameters>
                        <DeleteParameters>
                            <asp:Parameter Name="RoadID" Type="Int32" />
                        </DeleteParameters>
                        <UpdateParameters>
                            <asp:Parameter Name="Parent" Type="String" />
                            <asp:Parameter Name="RoadName" Type="String" />
                            <asp:Parameter Name="RoadID" Type="Int32" />
                        </UpdateParameters>
                    </asp:SqlDataSource> <My:MyGridView id="gv" runat="server" DataKeyNames="RoadID" DataSourceID="SqlDataSource2" Width="99%" TotalRowCount="0" SkinID="pager" AllowHoverSelect="False" AllowHoverEffect="False" MySortDirection="Ascending" AutoGenerateColumns="False" MouseOverColor BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal" EmptyDataText="目前無相關資料!!" ForeColor="#333333" ShowFooterWhenEmpty="False" OnRowDataBound="gv_RowDataBound">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></FooterStyle>

<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></HeaderStyle>

<EditRowStyle BackColor="#999999"></EditRowStyle>

<PagerStyle HorizontalAlign="Center" BackColor="#284775" ForeColor="White"></PagerStyle>

<EmptyDataRowStyle HorizontalAlign="Center"></EmptyDataRowStyle>

<AlternatingRowStyle BackColor="White" ForeColor="#284775"></AlternatingRowStyle>
<Columns>
<asp:TemplateField HeaderText="NO"><EditItemTemplate>
<asp:Label id="lblNO" runat="server" __designer:wfdid="w82"></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label id="lblNO" runat="server" __designer:wfdid="w81"></asp:Label>
</ItemTemplate>

<HeaderStyle Width="20px"></HeaderStyle>

<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="鄉鎮市" SortExpression="RegionName"><EditItemTemplate>
<asp:DropDownList id="ddlRegionID_Edit" runat="server" OnDataBound="ddlRegionID_Edit_DataBound" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="ddlRegionID_Edit_SelectedIndexChanged" DataValueField="RegionID" DataTextField="RegionName" AutoPostBack="True"></asp:DropDownList><asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ValidationGroup="vEdit" SetFocusOnError="True" ErrorMessage="請選擇鄉鎮市!!" Display="None" ControlToValidate="ddlRegionID_Edit" InitialValue="0"></asp:RequiredFieldValidator><asp:HiddenField id="hideRegionID" runat="server" Value='<%# Bind("Parent") %>'></asp:HiddenField><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:connStr %>"
                                SelectCommand="SELECT RegionID, RegionName, Parent, RegionType FROM Region WHERE (RegionType = @RegionType) ORDER BY Sequence,RegionName">
    <SelectParameters>
        <asp:Parameter DefaultValue="T" Name="RegionType" Type="String" />
    </SelectParameters>
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label id="Label1" runat="server" Text='<%# Eval("RegionName") %>' __designer:wfdid="w66"></asp:Label> 
</ItemTemplate>

<HeaderStyle Width="80px"></HeaderStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="道路總稱" SortExpression="RoadName"><EditItemTemplate>
<asp:TextBox id="TextBox2" runat="server" Width="350px" Text='<%# Bind("RoadName") %>' MaxLength="100" __designer:wfdid="w63"></asp:TextBox><asp:RequiredFieldValidator id="RequiredFieldValidator11" runat="server" ValidationGroup="vEdit" SetFocusOnError="True" InitialValue="0" ErrorMessage="請輸入道路總稱!!" Display="None" ControlToValidate="TextBox2" __designer:wfdid="w64"></asp:RequiredFieldValidator> 
</EditItemTemplate>
<ItemTemplate>
<asp:Label id="Label3" runat="server" Text='<%# Eval("RoadName") %>'></asp:Label> 
</ItemTemplate>

<HeaderStyle Width="120px"></HeaderStyle>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False"><EditItemTemplate>
<asp:LinkButton id="LinkButton1" runat="server" ValidationGroup="vEdit" Text="更新" CommandName="Update" CausesValidation="True"></asp:LinkButton>&nbsp;<asp:LinkButton id="LinkButton2" runat="server" Text="取消" CommandName="Cancel" CausesValidation="False"></asp:LinkButton> 
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton id="LinkButton1" runat="server" Text="編輯" CommandName="Edit" CausesValidation="False"></asp:LinkButton>&nbsp; <asp:LinkButton id="deletebutton" runat="server" Text="刪除" CommandName="Delete" CausesValidation="False"></asp:LinkButton><cc1:ConfirmButtonExtender id="ConfirmButtonExtender2" ConfirmText="確定要刪除?(相關案件將無法再對應!!)" runat="server" TargetControlID="deletebutton"></cc1:ConfirmButtonExtender>
</ItemTemplate>

<HeaderStyle Width="70px"></HeaderStyle>

<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="編輯道路細項">
<ItemTemplate>
<asp:LinkButton id="lbtnRoadItemName" runat="server" ForeColor="Blue" __designer:wfdid="w68">編輯道路細項</asp:LinkButton>
</ItemTemplate>

<HeaderStyle Width="80px"></HeaderStyle>
</asp:TemplateField>
</Columns>

<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333"></SelectedRowStyle>

<RowStyle BackColor="#F7F6F3" ForeColor="#333333"></RowStyle>
</My:MyGridView> </TD></TR></TBODY></TABLE>
            </ContentTemplate>
        </asp:UpdatePanel> 
                <asp:ValidationSummary ID="ValidationSummary1" runat="server" DisplayMode="List" 
            ShowMessageBox="True" ShowSummary="False" ValidationGroup="vInsert" />
        <asp:ValidationSummary ID="ValidationSummary2" runat="server" DisplayMode="List" 
            ShowMessageBox="True" ShowSummary="False" ValidationGroup="vEdit" />
</asp:Content>